//
//  ReadConfig.m
//  AutoCompilerManager
//
//  Created by Vescky on 13-7-11.
//  Copyright (c) 2013年 Vescky. All rights reserved.
//

#import "ReadConfig.h"

@implementation ReadConfig

+ (NSString*)readTmpPath {
    NSString *path = [[NSBundle mainBundle] pathForResource:@"config" ofType:@"plist"];
    NSDictionary *data = [[NSDictionary alloc] initWithContentsOfFile:path];
    NSString *rPath = [data objectForKey:@"TMP_PATH"];
    return [self formmatPath:rPath];
}

+ (NSString*)readAutoCompilerProductsPath {
    NSString *path = [[NSBundle mainBundle] pathForResource:@"config" ofType:@"plist"];
    NSDictionary *data = [[NSDictionary alloc] initWithContentsOfFile:path];
    NSString *rPath = [data objectForKey:@"AUTOCOMPILER_PRODUCTS_PATH"];
    return [self formmatPath:rPath];
}

+ (NSString*)readAutoCompilerCMDPathForSQ {
    NSString *path = [[NSBundle mainBundle] pathForResource:@"config" ofType:@"plist"];
    NSDictionary *data = [[NSDictionary alloc] initWithContentsOfFile:path];
    NSString *rPath = [data objectForKey:@"AUTOCOMPILER_CMD_PATH_FOR_SQ"];
    return [self formmatPath:rPath];
}

+ (NSString*)readRepoZipsPathForProd:(bool)isProd {
    NSString *path = [[NSBundle mainBundle] pathForResource:@"config" ofType:@"plist"];
    NSDictionary *data = [[NSDictionary alloc] initWithContentsOfFile:path];
    if (isProd) {
        return [data objectForKey:@"PROD_REPO"];
    }
    NSString *rPath = [data objectForKey:@"WIP_REPO"];
    return [self formmatPath:rPath];
}

+ (NSString*)readAutoCompilerCMDPath {
    NSString *path = [[NSBundle mainBundle] pathForResource:@"config" ofType:@"plist"];
    NSDictionary *data = [[NSDictionary alloc] initWithContentsOfFile:path];
    NSString *rPath = [data objectForKey:@"AUTOCOMPILER_CMD_PATH"];
    return [self formmatPath:rPath];
}

+ (NSString*)readErrorReportsPath {
    NSString *path = [[NSBundle mainBundle] pathForResource:@"config" ofType:@"plist"];
    NSDictionary *data = [[NSDictionary alloc] initWithContentsOfFile:path];
    NSString *rPath = [data objectForKey:@"ERROR_REPORTS_PATH"];
    return [self formmatPath:rPath];
}

+ (NSString*)readTestIp {
    NSString *path = [[NSBundle mainBundle] pathForResource:@"config" ofType:@"plist"];
    NSDictionary *data = [[NSDictionary alloc] initWithContentsOfFile:path];
    NSString *rPath = [data objectForKey:@"TEST_IPS"];
    return [self formmatPath:rPath];
}

+ (NSString*)readConfigByKey:(NSString*)key {
    NSString *path = [[NSBundle mainBundle] pathForResource:@"config" ofType:@"plist"];
    NSDictionary *data = [[NSDictionary alloc] initWithContentsOfFile:path];
    NSString *rPath = [data objectForKey:key];
    return [self formmatPath:rPath];
}

+ (id)readRawConfigByKey:(NSString*)key {
    NSString *path = [[NSBundle mainBundle] pathForResource:@"config" ofType:@"plist"];
    NSDictionary *data = [[NSDictionary alloc] initWithContentsOfFile:path];
    return [data objectForKey:key];
}

+ (NSString*)readApkAndIpaStoragePathByIP:(NSString*)ipAddress {
    NSString *path = [[NSBundle mainBundle] pathForResource:@"config" ofType:@"plist"];
    NSDictionary *data = [[NSDictionary alloc] initWithContentsOfFile:path];
    NSDictionary *pathsDict = [data objectForKey:@"PRODUCTS_DOWNLOAD_PATH"];
    if ([pathsDict objectForKey:ipAddress]) {
        return [self formmatPath:[pathsDict objectForKey:ipAddress]];
    }
    else {
        return [self formmatPath:[pathsDict objectForKey:@"default"]];
    }
}

+ (NSString*)formmatPath:(NSString*)path {
    path = [path stringByReplacingOccurrencesOfString:@" " withString:@""];
    path = [path stringByReplacingOccurrencesOfString:@"\n" withString:@""];
    path = [path stringByReplacingOccurrencesOfString:@"\t" withString:@""];
    return path;
}



@end
